<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>弹出层效果</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #overlay{
            width: 100%;
            height: 100%;
            background: #000;
            opacity: 0.5;
            filter: alpha(opacity=50);
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }
        #win{
            width: 500px;
            height: 250px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -250px;
            margin-top: -125px;
            border: 4px solid #f90;
            background: #fff;
            display: none;
        }
        h2{
            width: 100%;
            height: 40px;
            background: #FC0;
            border-bottom: 6px solid #f90;
            text-align: right;
        }
        #close{
            /* float: right; */
            margin-right: 10px;
            cursor: pointer;
            font-size: 14px;
            background-color: #fff;
            padding: 0 4px;
            line-height: 20px;
        }
        p{
            margin: 100px;
        }
    </style>
    <script>
        window.onload = function(){
            var oBtn = document.getElementsByTagName("button")[0];
            var oLay = document.getElementById("overlay");
            var oWin = document.getElementById("win");
            var oClose = document.getElementById("close");
            
            oBtn.onclick = function(){
                oLay.style.display = "block"
                oWin.style.display =  "block";
            }
            // 问题： 一开始点两下才会出现

            oClose.onclick = function(){
                oWin.style.display = "none";
                oLay.style.display = "none";
            }
        }
    </script>
</head>

<body>
    <div id="overlay"></div>
    <div id="win">
        <h2>
            <span id="close">×</span>
        </h2>
    </div>
    <center>
        <button style="cursor: pointer;">弹出层效果</button>
    </center>
    <div class="div1"></div>

</body>

</html>